<template>
  <el-select v-bind="$attrs" v-model="value" clearable filterable @change="change">
    <el-option v-for="item in importerOptions" :key="item.id" :label="item.importer_company_name"
      :value="item.id" />
  </el-select>
</template>
<script setup>
import useCommonStore from "@/store/modules/common";
const commonStore = useCommonStore();
const importerOptions = computed(() => {
  if (!commonStore.importerOptions) {
    commonStore.getImporterList()
  }
  return commonStore.importerOptions || []
});
const props = defineProps({
  modelValue: [String, Number, Array],
});

const value = ref()
watch(() => props.modelValue, (val) => {
  value.value = val
})
const emit = defineEmits(['update:modelValue', 'change'])
const change = (val) => {
  const item = importerOptions.value.find(i => i.id == val)
  emit('change', item || '')
  emit('update:modelValue', val)
}

</script>